package ru.ifmo.tanya.core.users;

import org.jdom.Element;


public class User {

    private final int id;
    private final String name;
    private final UserRole role;
    private final String extension;

    public User(int id, String name, UserRole role, String extension) {
        this.id = id;
        this.name = name;
        this.role = role;
        this.extension = extension;
    }

    public int getId() {
        return id;
    }

    public UserRole getRole() {
        return role;
    }

    public String getName() {
        return name;
    }

    public String getExtension() {
        return extension;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        if (name != null ? !name.equals(user.name) : user.name != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return name != null ? name.hashCode() : 0;
    }

    public Element toXml() {
        return new Element("user")
                .setAttribute("name", name)
                .setAttribute("extension", extension)
                .setAttribute("id", id + "");
    }
}
